package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.MeterBoreBean;
import com.koron.css2.baseConfig.mapper.MeterBoreMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import com.koron.util.Tools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 水表口径-添加
 * @author 李攀
 *
 */
public class MeterBoreAdd implements ServerInterface{

	private static Logger logger = LogManager.getLogger(MeterBoreAdd.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MeterBoreMapper mapper = factory.getMapper(MeterBoreMapper.class);
		MeterBoreBean bean = new MeterBoreBean();
		try {
			bean = JsonUtils.objectToPojo(req.getData(), MeterBoreBean.class);
		} catch (Exception e) {
			logger.error("非法参数", e);
			return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
		}
		// 校验字段重复
		if (mapper.check("bore_name", bean.getBoreName()) > 0) {
			return MessageBean.create(Constant.ILLEGAL_PARAMETER,"水表口径名称：" + bean.getBoreName() + "的信息已存在。", void.class);
		}
		bean.setId(Tools.getObjectId());;
		bean.setCreateName(userInfo.getUserInfo().getName());
		bean.setCreateTime(CommonUtils.getCurrentTime());
		bean.setCreateAccount(userInfo.getUserInfo().getAcount());
		
		mapper.insertMeterBore(bean);
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	}
}